from random import *

def generateInstrument(num):
    outString = "<music instrument = \""+str(num)+"\">\n"
    for i in range(length):
        outString += generateBar()
    outString += "</music>\n"
    return outString


def generateBar():
    length = 0
    octave = randint(-1,9)
    outString = "<bar>\n<sequence octave =\""+str(octave)+"\">"
    while(length<32):
        outString += notes[randint(0, 12)]
        l1 = lengths[randint(0,5)]
        if((l1+length)>32):
            l1 = (l1-((l1+length)%32))
        outString += str(l1)
        length += l1
    outString += "</sequence>\n</bar>\n"
    return outString

notes = ['c','C','d','D','e','f','F','g','G','a','A','b','!']
lengths =[1,2,4,8,16,32] 
instruments = randint(1,10)
length = randint(30,100)
finalOut = "<song length =\""+str(length)+"\" instruments = \""+str(instruments)+"\">\n"

for i in range(instruments):
    finalOut += generateInstrument(i+1)

finalOut += "</song>"

f = open("src/newMusic.xml", "w")
f.write(finalOut)



    
        

